package com.example.b_308.myapplication.model.base;

import com.alibaba.fastjson.JSONArray;
import com.example.b_308.myapplication.comment.utils.JsonUtils;
import com.example.b_308.myapplication.comment.utils.L;
import com.example.b_308.myapplication.model.Department;
import com.example.b_308.myapplication.model.base.BaseModel;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by B-308 on 2017/11/20.
 */
public class BaseCompany extends BaseModel {
    String id;
    String name;
    String address;
    String telephone;
    Integer scale;
    String create_time;
    List<Department> departments;


    public String getId() {
        if (null == id)
            id = getStr("id");
        return id;
    }

    public List<Department> getDepartments() {
        if (null == departments) {
            departments = new ArrayList<>();
            departments = JsonUtils.jsonToT(getStr("departments"), List.class);

        }
        return departments;
    }

    public void setDepartments(List<Department> departments) {
        this.departments = departments;
        JSONArray jsonArray = new JSONArray();
        for (Department department : departments) {
            jsonArray.add(JsonUtils.tToJson(department));
        }
        L.d(jsonArray.toJSONString());
        put("departments", jsonArray.toJSONString());
    }

    public String getName() {
        if (null == name)
            name = getStr("name");
        return name;
    }

    public String getAddress() {
        if (null == address)
            address = getStr("address");
        return address;
    }

    public String getTelephone() {
        if (null == telephone)
            telephone = getStr("telephone");
        return telephone;
    }

    public Integer getScale() {
        if (null == scale)
            scale = getInt("scale");
        return scale;
    }

    public String getCreate_time() {
        if (null == create_time)
            create_time = getStr("create_time");
        return create_time;
    }

    public void setId(String id) {
        put("id", id);
        this.id = id;
    }

    public void setName(String name) {
        put("name", name);
        this.name = name;
    }

    public void setAddress(String address) {
        put("address", address);
        this.address = address;
    }

    public void setTelephone(String telephone) {
        put("telephone", telephone);
        this.telephone = telephone;
    }

    public void setScale(Integer scale) {
        put("scale", scale);
        this.scale = scale;
    }

    public void setCreate_time(String create_time) {
        put("create_time", create_time);
        this.create_time = create_time;
    }

}
